package test;

// 我们的产品类
public class Product {
    private String property1;
    private String property2;
    private String property3;

    public void setProperty1(String property1) {
        this.property1 = property1;
    }

    public void setProperty2(String property2) {
        this.property2 = property2;
    }

    public void setProperty3(String property3) {
        this.property3 = property3;
    }

    @Override
    public String toString() {
        return "Product{" +
                "property1='" + property1 + '\'' +
                ", property2='" + property2 + '\'' +
                ", property3='" + property3 + '\'' +
                '}';
    }
}

// 建造者接口
interface Builder {
    void buildProperty1(String property1);
    void buildProperty2(String property2);
    void buildProperty3(String property3);
    Product getProduct();
}

// 具体建造者
class ConcreteBuilder implements Builder {
    private Product product = new Product();

    @Override
    public void buildProperty1(String property1) {
        product.setProperty1(property1);
    }

    @Override
    public void buildProperty2(String property2) {
        product.setProperty2(property2);
    }

    @Override
    public void buildProperty3(String property3) {
        product.setProperty3(property3);
    }

    @Override
    public Product getProduct() {
        return product;
    }
}

// 指挥者类
class Director {
    public void construct(Builder builder) {
        builder.buildProperty1("value1");
        builder.buildProperty2("value2");
        builder.buildProperty3("value3");
    }
}

// 测试类
class Test {
    public static void main(String[] args) {
        Director director = new Director();
        Builder builder = new ConcreteBuilder();

        director.construct(builder);
        Product product = builder.getProduct();

        System.out.println(product);
    }
}

